package com.sd.view;

import android.content.Context;
import android.database.Cursor;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CursorAdapter;
import android.widget.TextView;

import com.alex.database.BookDatabaseHelper.Bookmark_TB;
import com.sd.activity.R;

/**
 * 
 * 章节适配器
 * 
 * @author Alex.Lu
 * 
 */
public class BookMarkAdpter extends CursorAdapter {

	public BookMarkAdpter(Context context, Cursor c) {
		super(context, c);
	}

	@Override
	public void bindView(View view, Context context, Cursor cursor) {
		// TODO Auto-generated method stub
		
		String name = cursor.getString(cursor.getColumnIndex(Bookmark_TB.BOOKMARK_MARK));
		Log.d("bindView", "name:"+name);
		TextView num = (TextView) view.findViewById(R.id.chapter_num);
		num.setText(name);
		// TextView nameTV = (TextView) view.findViewById(R.id.chapter_name);
		// nameTV.setText(str[1]);
		if (cursor.getPosition() % 2 == 0) {
			view.setBackgroundResource(R.color.white);
		} else {
			view.setBackgroundResource(R.color.grey);
		}
	}

	@Override
	public View newView(Context context, Cursor cursor, ViewGroup parent) {
		// TODO Auto-generated method stub
		final LayoutInflater inflater = LayoutInflater.from(context);
		final View view = (View) inflater.inflate(R.layout.chpater_list,
				parent, false);
		return view;
	}

}
